<!-- 下单信息填写 -->
<template>
	<view style="width: 100%;height: 100%;">
		<uni-nav-bar title="下单信息填写" @clickLeft="back" left-icon="left" backgroundColor="#fff" color="#000"
			statusBar="true">
		</uni-nav-bar>
		<view class="service-price">
			<view class="title">
				翻耕整地服务
			</view>
			<view class="price">
				服务价格：{{price}}元/1亩
			</view>
		</view>
		<scroll-view class="scrollheight" scroll-y="true" :style="{height:setcollapseheight() - 210 + 'px'}"
			style="margin-top: 10rpx;">
			<u--form labelPosition="left" :model="model" :rules="rules" ref="form">
				<u-form-item>
					<view style="font-size: 24rpx;color: #222;">
						请选择您需服务的作物品种：
					</view>
				</u-form-item>
				<u-form-item prop="formData.type">
					<u-radio-group placement="row" size="32" style="display: flex;flex-wrap: wrap;">
						<u-radio labelSize="24" iconSize="24" :customStyle="{marginBottom: '8px'}"
							v-for="(item, index) in checkboxList" :key="index" :label="item.plantTypeName"
							:name="item.plantTypeId" @change="checkboxChange(index)" shape="square"></u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item>
					<view style="font-size: 24rpx;color: #222;">
						请填写基本信息：
					</view>
				</u-form-item>
				<!-- 1.联系人 -->
				<u-form-item label="联系人" prop="formData.FGZD_LXR">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/machinery/xingming.png" mode="heightFix"></image>
					</view>
					<u--input v-model="model.formData.FGZD_LXR" placeholder='请输入姓名' border="none"></u--input>
				</u-form-item>
				<!-- 2.联系电话 -->
				<u-form-item label="联系电话" prop="formData.FGZD_LXDH">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/machinery/lianxidianhua.png" mode="heightFix">
						</image>
					</view>
					<u-input v-model="model.formData.FGZD_LXDH" :type="'number'" placeholder='请输入电话号'
						border="none"></u-input>
				</u-form-item>
				<!-- 3.所在区域-省市区 -->
			<!-- 	<u-form-item label="所在区域" prop="formData.AllName">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/service-order/quyu.png" mode="heightFix"></image>
					</view>
					<picker mode="multiSelector" :range="areaList" range-key="name" :value="value"
						@columnchange="columnchange" @change="bindPickerChange">
						<u--input v-model="model.formData.AllName" style="pointer-events: none" disabled
							disabledColor="#ffffff" border="none" placeholder='请选择所在区域'></u--input>
					</picker>
					<view  @click="goMap">
						<u--input v-model="model.formData.AllName" style="pointer-events: none;flex-wrap: wrap;" disabled
							disabledColor="#ffffff" border="none" placeholder='请选择所在区域'></u--input>
					</view>
				</u-form-item> -->
				<!-- 4.具体地址 -->
				<!-- <u-form-item label="详细地址" prop="formData.FGZD_JTDZ" class="fullAddress">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/service-order/jutidizhi.png" mode="heightFix">
						</image>
					</view>
					<u--textarea class="textarea" v-model="model.formData.FGZD_JTDZ" :disabled="true" placeholder='请输入具体地址' border="none"
						style="display: flex;"></u--textarea>
				</u-form-item> -->
				<!-- 5.服务亩数 -->
				<u-form-item label="服务亩数" prop="formData.FGZD_FWMS">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/service-order/mushu.png" mode="heightFix">
						</image>
					</view>
					<u--input v-model="model.formData.FGZD_FWMS" type="number" placeholder='请输入服务亩数'
						border="none"></u--input>
				</u-form-item>
				<!-- 6.1期望服务开始时间 -->
				<u-form-item label="期望开始时间" prop="formData.startTime" @click="showTimeDialog1">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/service-order/calendar.png" mode="heightFix">
						</image>
					</view>
					<view style="pointer-events: none;">
						<u--input v-model="model.formData.startTime" readonly placeholder='请输入期望开始服务时间'
							border="none"></u--input>
					</view>
					<u-datetime-picker :show="showTimeStartFlag" v-model="startTime" mode="datetime"
						@confirm="getShowStartTime" :formatter='formatter' @cancel="showTimeStartFlag=false">
					</u-datetime-picker>
				</u-form-item>
				<!-- 6.2期望服务结束时间 -->
				<u-form-item label="期望结束时间" prop="formData.endTime" @click="showTimeDialog2">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/service-order/calendar.png" mode="heightFix">
						</image>
					</view>
					<view style="pointer-events: none;">
						<u--input v-model="model.formData.endTime" placeholder='请输入期望结束服务时间' border="none"></u--input>
					</view>
					<u-datetime-picker :show="showTimeEndFlag" v-model="startTime" mode="datetime"
						@confirm="getShowEndTime" :formatter='formatter' @cancel="showTimeEndFlag=false">
					</u-datetime-picker>
				</u-form-item>
				<!-- 7.自选服务农机prop="formData.machinery" -->
				<u-form-item label="自选服务农机" @click="showpop" :prop="equipmentFlag ? 'formData.machinery' : ''"
					v-show="isChooseMachinery >= 1 && this.equipmentList.length > 0">
					<view class="left-image">
						<image class="left-img" src="@/subPage1/static/service-order/machinery.png" mode="heightFix">
						</image>
					</view>
					<view style="pointer-events: none;">
						<u--input v-model="model.formData.machinery" placeholder='选择农机' border="none"></u--input>
					</view>

				</u-form-item>
			</u--form>

		</scroll-view>
		<view class="total-prices">
			<view class="prices">
				<view class="title">
					预计价格：
				</view>
				<view class="price">
					{{(this.model.formData.FGZD_FWMS * this.price).toFixed(2)}}元
				</view>
			</view>
		</view>
		<view class="submit">
			<button @click="buyOrder()" class="submit-btn">
				<text>下单</text>
			</button>
		</view>
		<u-popup class="popUp" :show="showPop" :round="10" mode="bottom" width="100%" height="100%" :closeable="false"
			@close="showPop=false">
			<view class="popUpOperate">
				<view class="center">
					自选农机
				</view>
			</view>
			<scroll-view scroll-y="true" :style="{height:setcollapseheight() - 130 + 'px'}" style="margin-top: 10rpx;">
				<view class="popItem" v-for="item in equipmentList" :key="item.id" @click="popConfirm(item)">
					<view class="first" v-if="item.pictureList !== null">
						<view class="popItemTop" v-for="(it,itIndex) in item.pictureList" :key="itIndex">
							<image :src="it" mode=""></image>
						</view>
					</view>
					<view class="first" v-else>
						<view class="popItemTop">
							<template v-if="item.equipmentName.includes('旋')">
								<image src="@/static/machinery/xuangeng.png" mode=""></image>
							</template>
							<template v-else-if="item.equipmentName.includes('拖拉')">
								<image src="@/static/machinery/tuola.png" mode=""></image>
							</template>
							<template v-else-if="item.equipmentName.includes('打捆')">
								<image src="@/static/machinery/dakun.png" mode=""></image>
							</template>
							<template v-else-if="item.equipmentName.includes('插秧')">
								<image src="@/static/machinery/chayang.png" mode=""></image>
							</template>
							<template v-else-if="item.equipmentName.includes('洒肥')">
								<image src="@/static/machinery/safei.png" mode=""></image>
							</template>
							<template v-else>
								<image src="@/static/machinery/shouge.png" mode=""></image>
							</template>
						</view>
					</view>
					<view class="tip">
						*图片仅供参考，以实际农机为准
					</view>
					<view class="title">
						{{item.equipmentName}}
					</view>
				</view>
			</scroll-view>
		</u-popup>
	</view>

</template>

<script>
	import {
		addressList
	} from '@/subPage1/plugins/address.js'
	import API from '@/api/socialized-servce/farm-service/normalUser/serviceSelect/service-organization/information-filling/index.js'
	import {
		socializedBaseurl
	} from '@/config/baseUrl.js'
	export default {
		data() {
			return {
				startTime: Number(new Date()),
				svcObjId: '',
				svcClassId: '',
				price: 0,
				plantTypeIds: [],
				equipmentList: [],
				checkboxList: [],
				model: {
					formData: {
						type: [],
						typeName: [],
						FGZD_LXR: '',
						FGZD_LXDH: '',
						FGZD_SZQY: [],
						FGZD_JTDZ: '',
						FGZD_FWMS: '',
						AllName: '',
						provinceId: '',
						cityId: '',
						areaId: '',
						startTime: '',
						machinery: '',
						machineryName: ''
					}
				},
				rules: {
					'formData.type': {
						type: 'array',
						validator: (rule, value, callback) => {
							if (this.model.formData.type.length > 0) {
								return true
							} else {
								if (this.checkboxList.length > 0) {
									return false
								} else {
									return true
								}
							}
						},
						required: true,
						message: '请选择需服务的作物品种',
						trigger: ['change']
					},
					'formData.FGZD_LXR': {
						type: 'string',
						required: true,
						message: '请输入姓名',
						trigger: ['blur', 'change']
					},
					'formData.FGZD_LXDH': [{
							type: 'number',
							required: true,
							message: '联系方式不能为空',
							trigger: ['blur', 'change']
						},
						{
							type: 'string',
							validator: (rule, value, callback) => {
								if (value.length <= 11) {
									if (value != '') {
										return this.$u.test.mobile(value)
									}
								} else {
									return false
								}
							},
							message: '手机号格式不对,请输入正确的手机号',
							trigger: ['blur', 'change']
						}
					],
					'formData.AllName': {
						type: 'string',
						required: true,
						message: '所在区域不能为空',
						trigger: ['blur', 'change']
					},
					'formData.FGZD_JTDZ': {
						type: 'string',
						required: true,
						message: '地址不能为空',
						trigger: ['blur', 'change']
					},
					'formData.FGZD_FWMS': [{
							type: 'number',
							required: true,
							message: '服务亩数不能为空',
							trigger: ['blur', 'change']
						},
						{
							type: 'number',
							validator: (rule, value, callback) => {
								if (this.model.formData.FGZD_FWMS) {
									let str = `${this.model.formData.FGZD_FWMS}`
									if (str.split('.')[1].length > 2) {
										return false
									} else {
										return true
									}
								} else {
									return true
								}
							},
							message: '只能保留两位小数',
							trigger: ['blur', 'change']
						}
					],
					'formData.startTime': [{
							type: 'string',
							required: true,
							message: '期望开始时间不能为空',
							trigger: ['blur', 'change']
						},
						{
							type: 'string',
							validator: (rule, value, callback) => {
								if (this.model.formData.endTime) {
									if (new Date(value).getTime() < new Date(this.model.formData.endTime)
										.getTime()) {
										return true
									} else {
										return false
									}
								} else {
									return true
								}
							},
							message: '期望开始时间不能大于等于期望结束时间',
							trigger: ['blur', 'change']
						}
					],
					'formData.endTime': [{
							type: 'string',
							required: true,
							message: '期望结束时间不能为空',
							trigger: ['blur', 'change']
						},
						{
							type: 'string',
							validator: (rule, value, callback) => {
								if (this.model.formData.startTime) {
									if (new Date(value).getTime() > new Date(this.model.formData.startTime)
										.getTime()) {
										return true
									} else {
										return false
									}
								} else {
									return true
								}
							},
							message: '期望结束时间不能小于等于期望开始时间',
							trigger: ['blur', 'change']
						}
					],
					'formData.machinery': {
						type: 'string',
						required: true,
						message: '请选择农机',
						trigger: ['blur', 'change']
					}
				},
				// 省市区
				areaList: [],
				value: [0, 0, 0],
				index: 0,
				AllAddress: addressList,
				selectVal: ['', '', ''],
				// 期望开始时间
				showTimeStartFlag: false,
				// 期望结束时间
				showTimeEndFlag: false,
				showPop: false,
				isChooseMachinery: 0,
				svcObjIdPropertyMap: [],
				equipmentId: '',
				equipmentIdList: [],
				equipmentFlag: false,
				propertiesKey: [],
				checkLessee: false//租户
			}
		},
		created() {
			this.svcObjIdPropertyMap = uni.getStorageSync('svcObjIdPropertyMap')
			this.svcClassId = uni.getStorageSync('svcClassId')
			for (let k in this.svcObjIdPropertyMap) {
				this.svcObjIdPropertyMap[k].forEach(el => {
					if (el.expression === 'relatePlant') {
						this.plantTypeIds = [...this.plantTypeIds, ...el.textValue.split(',')]
						this.plantTypeIds = [...new Set(this.plantTypeIds)]
					}
				})
			}
			this.setcollapseheight()
			// 省市区
			// this.initSelect()
			// let address = uni.getStorageSync('formatted_address')
			// var reg = /.+?(省|市|自治区|自治州|县|区)/g;
			// let arr = address.match(reg).toString().split(",");
			// console.log(arr,addressList, 'mm');
			// this.model.formData.AllName = `${arr[0]}${arr[1]}${arr[2]}`
			// this.model.formData.FGZD_JTDZ = address
			// addressList.forEach(item=>{
			// 	if(item.name === arr[0]) {
			// 		this.model.formData.provinceId = item.provinceId
			// 	}
			// 	item.city.forEach(item1=>{
			// 		if(item1.name === arr[1] && item.name === arr[0]) {
			// 			this.model.formData.cityId = item1.cityId
			// 		}
			// 		if(item1.name === '市辖区' && item.name === arr[0]) {
			// 			this.model.formData.cityId = item1.cityId
			// 		}
					
			// 		item1.area.forEach(item2=>{
			// 			if(item2.name === arr[2] && item.name === arr[0]) {
			// 				this.model.formData.areaId = item2.areaId
			// 			}
			// 		})
			// 	})
				
			// })
			let userInfo = JSON.parse(uni.getStorageSync('userServerInfo'))
			this.checkLessee = userInfo.checkLessee//租户
			this.model.formData.FGZD_LXDH = userInfo.phoneNumber
			this.model.formData.FGZD_LXR = userInfo.userName
			let myarableInfo = uni.getStorageSync('myarableInfo')
			this.model.formData.FGZD_JTDZ = myarableInfo.address
			this.model.formData.AllName = myarableInfo.regionStr
			this.model.formData.provinceId = myarableInfo.provinceId
			this.model.formData.cityId = myarableInfo.cityId
			this.model.formData.areaId = myarableInfo.areaId
		},
		mounted() {
			this.getCropVariety()
			this.getPropertiesKey()
		},
		methods: {
			goMap() {
				return
				uni.navigateTo({
					url: `/subPage1/map1/map1`
				})
			},
			async getPropertiesKey() {
				let res = await API.queryPropertiesKey(this.svcClassId)
				if(res.code === 200) {
					this.propertiesKey = res.data
				}
				
			},
			checkboxChange(e) {
				// 重置农机选择
				this.equipmentIdList = []
				this.model.formData.machinery = ''
				this.model.formData.machineryName = ''
				this.equipmentId = ''

				this.model.formData.type = []
				this.model.formData.typeName = []
				let el = this.checkboxList[e]
				this.model.formData.type.push(el.plantTypeId)
				this.model.formData.typeName.push(el.plantTypeName)
				if (this.model.formData.type[0] && this.equipmentId) {
					for (let k in this.svcObjIdPropertyMap) {
						const itemIndex = this.svcObjIdPropertyMap[k].findIndex(item => {
							if (item.expression === 'relatePlant' && item.textValue ==
								`${this.model.formData.type[0]}`) {
								return true
							}
						})
						const itemIndex2 = this.svcObjIdPropertyMap[k].findIndex(item => {
							if (item.expression === 'relateDevice' && item.textValue == `${this.equipmentId}`) {
								return true
							}
						})
						if (itemIndex !== -1 && itemIndex2 !== -1) {
							this.svcObjIdPropertyMap[k].forEach(el => {
								if (el.expression === 'unitPrice') {
									this.price = el.numValue
								}
							})
						}
					}
				} else if (this.model.formData.type[0]) {
					let num = 0
					for (let k in this.svcObjIdPropertyMap) {
						const itemIndex = this.svcObjIdPropertyMap[k].findIndex(item => {
							if (item.expression === 'relatePlant' && item.textValue ==
								`${this.model.formData.type[0]}`) {
								return true
							}
						})
						if (itemIndex !== -1) {
							this.svcObjId = k
							this.svcObjIdPropertyMap[k].forEach(el => {
								if (el.expression === 'unitPrice') {
									this.price = el.numValue
									num += 1
								}
								if (el.expression === 'selfSerivceDevice') {
									this.isChooseMachinery += el.textValue * 1
								}
								if (el.expression === 'relateDevice') {
									this.equipmentIdList = [...this.equipmentIdList, ...el.textValue.split(',')]
								}
							})
						}
					}
					console.log(this.equipmentIdList);
					this.getEquipmentData(this.equipmentIdList)
					if (num > 1) {
						this.price = 0
						this.equipmentFlag = true
					} else {
						this.equipmentFlag = false
						this.$refs.form.clearValidate('formData.machinery')
					}
				}
				this.$refs.form.validateField('formData.type')
			},
			// 获取服务农机数据
			async getEquipmentData(arr) {
				let params = {
					idList: arr
				}
				let res = await API.queryEquip(params)
				if (res.code === 200) {
					this.equipmentList = res.data
				}
			},
			// 获取作物品种
			async getCropVariety() {
				let params = {
					plantTypeIds: this.plantTypeIds
				}
				let res = await API.queryCropVariety(params)
				if (res.code === 200) {
					this.checkboxList = res.data
				}
			},
			hideKeyboard() {
				uni.hideKeyboard()
			},
			// 省市区
			bindPickerChange(e) {
				this.model.formData.provinceId = addressList[this.value[0]].provinceId
				this.model.formData.cityId = addressList[this.value[0]].city[this.value[1]].cityId
				this.model.formData.areaId = addressList[this.value[0]].city[this.value[1]].area[this.value[2]].areaId
				this.$refs.form.validateField('formData.AllName')
			},
			columnchange(d) {
				this.updateSelectIndex(d.detail.column, d.detail.value) // 更新选择索引
					.updateSourceDate() // 更新源数据
					.updateAddressDate() // 更新结果数据
			},
			initSelect() {
				this.updateSourceDate() // 更新源数据
				this.updateAddressDate() // 更新结果数据
			},
			updateSourceDate() {
				this.areaList = []
				this.areaList[0] = this.AllAddress.map(obj => {
					return {
						name: obj.name
					}
				})
				this.areaList[1] = this.AllAddress[this.value[0]].city.map(obj => {
					return {
						name: obj.name
					}
				})
				this.areaList[2] = this.AllAddress[this.value[0]].city[this.value[1]].area.map(obj => {
					return {
						name: obj.name
					}
				})
				return this
			},
			updateSelectIndex(column, value) {
				let arr = JSON.parse(JSON.stringify(this.value))
				arr[column] = value
				if (column === 0) {
					arr[1] = 0
					arr[2] = 0
				}
				if (column === 1) {
					arr[2] = 0
				}
				this.value = arr
				return this
			},
			updateAddressDate() {
				this.selectVal[0] = this.areaList[0][this.value[0]].name
				this.selectVal[1] = this.areaList[1][this.value[1]].name
				this.selectVal[2] = this.areaList[2][this.value[2]].name

				if (this.value[0] == 0 && this.value[1] == 0 && this.value[2] == 0) {
					this.model.formData.AllName = ''
				} else {
					this.model.formData.AllName = `${this.selectVal[0]}${this.selectVal[1]}${this.selectVal[2]}`
				}
				// console.log(this.model.formData);
			},
			// 期望开始时间
			showTimeDialog1() {
				this.showTimeStartFlag = true
			},
			// 期望结束时间
			showTimeDialog2() {
				this.showTimeEndFlag = true
			},
			getShowStartTime(e) {
				// console.log(e, '@@');
				this.model.formData.startTime = this.getTime(e.value)
				this.showTimeStartFlag = false
				this.$refs.form.validateField('formData.startTime')
			},
			getShowEndTime(e) {
				this.model.formData.endTime = this.getTime(e.value)
				// console.log(this.model.formData.endTime);
				this.showTimeEndFlag = false
				this.$refs.form.validateField('formData.endTime')
			},
			formatter(type, value) {
				if (type === 'year') {
					return value + '年'
				} else if (type === 'month') {
					return value + '月'
				} else if (type === 'day') {
					return value + '日'
				} else if (type === 'hour') {
					return value + '时'
				} else if (type === 'minute') {
					return value + '分'
				} else if (type === 'second') {
					return value + '秒'
				}
				return value
			},
			// 时间戳计算
			getTime(timestamp) {
				// 时间戳转化
				let date = new Date()
				if (timestamp) date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000

				const Y = date.getFullYear() + '-';
				const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';

				const h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
				const m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
				const s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
				return Y + M + D + h + m;
			},
			getTimes(timestamp) {
				// 时间戳转化
				let date = new Date()
				if (timestamp) date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000

				const Y = date.getFullYear();
				const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
				const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());

				const h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
				const m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
				const s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
				return `${Y}${M}${D}${h}${m}${s}`;
			},
			// pop
			showpop() {
				this.showPop = true
			},
			// 自选农机
			popConfirm(item) {
				this.equipmentId = item.id
				this.model.formData.machinery = item.equipmentName
				this.model.formData.machineryName = item.id
				this.$refs.form.validateField('formData.machinery')
				this.showPop = false
				if (this.model.formData.type[0] && this.equipmentId) {
					for (let k in this.svcObjIdPropertyMap) {
						const itemIndex = this.svcObjIdPropertyMap[k].findIndex(item => {
							if (item.expression === 'relatePlant' && item.textValue ==
								`${this.model.formData.type[0]}`) {
								return true
							}
						})

						const itemIndex2 = this.svcObjIdPropertyMap[k].findIndex(item => {
							if (item.expression === 'relateDevice' && item.textValue.includes(this.equipmentId)) {
								return true
							}
						})
						if (itemIndex !== -1 && itemIndex2 !== -1) {
							this.svcObjId = k
							this.svcObjIdPropertyMap[k].forEach(el => {
								if (el.expression === 'unitPrice') {
									this.price = el.numValue
								}
							})
						}
					}
				}
			},
			// 下单
			buyOrder() {
				// console.log(this.model.formData.startTime); return
				this.$refs.form.validate().then(async (res1) => {
					console.log("提交表单信息:" + JSON.stringify(this.model.formData))
					// uni.$u.toast('校验通过')
					// 调用服务端入表接口
					let {
						FGZD_LXR,
						FGZD_LXDH,
						provinceId,
						cityId,
						areaId,
						AllName,
						FGZD_JTDZ,
						FGZD_FWMS,
						startTime,
						endTime,
						type,
						typeName,
						machinery,
						machineryName
					} = this.model.formData
					let params = {
						svcObjId: this.svcObjId,
						svcClassId: this.svcClassId,
						priceRide: FGZD_FWMS,
						serviceBegin: this.getTimes(startTime),
						serviceEnd: this.getTimes(endTime),
						properties: {
						// 	FGZD_LXR: FGZD_LXR,
						// 	FGZD_LXDH: FGZD_LXDH,
						// 	FGZD_SZQY: `${provinceId},${cityId},${areaId}`,
						// 	FGZD_SZQYMC: AllName,
						// 	FGZD_JTDZ: `${FGZD_JTDZ}`,
						// 	FGZD_FWMS: FGZD_FWMS,
						// 	FGZD_FWSJ: this.getTimes(startTime),
						// 	FGZD_FWSJ_BEGIN: this.getTimes(startTime),
						// 	FGZD_FWSJ_END: this.getTimes(endTime),
						// 	FGZD_GLZW: type.join(','),
						// 	FGZD_GLZWMC: typeName.join(','),
						// 	FGZD_GLNJ: machineryName,
						// 	FGZD_GLNJMC: machinery
						},
					}
					this.propertiesKey.forEach(el=>{
						let key = el.propertyCode
						if(el.expression === 'contactName') {
							params.properties[key] = FGZD_LXR
						}
						if(el.expression === 'contactPhone') {
							params.properties[key] = FGZD_LXDH
						}
						if(!this.checkLessee) {
							if(el.expression === 'area') {
								params.properties[key] = `${provinceId},${cityId},${areaId}`
							}
						}
						if(el.expression === 'addressArea') {
							params.properties[key] = AllName
						}
						if(el.expression === 'addressInfo') {
							params.properties[key] = `${FGZD_JTDZ}`
						}
						if(el.expression === 'rate') {
							params.properties[key] = FGZD_FWMS
						}
						if(el.expression === 'serviceBegin') {
							params.properties[key] = this.getTimes(startTime)
						}
						if(el.expression === 'serviceEnd') {
							params.properties[key] = this.getTimes(endTime)
						}
						if(el.expression === 'relatePlant') {
							params.properties[key] = type.join(',')
						}
						if(el.expression === 'orderObjName') {
							params.properties[key] = typeName.join(',')
						}
						if(el.expression === 'relateDevice') {
							params.properties[key] = machineryName
						}
					})
					// console.log(params);
					// return;
					let res = await API.serviceOrder(params)
					if (res.code === 200) {
						uni.showToast({
							title: '下单成功',
							icon: 'success'
						})
						uni.setStorageSync('formServiceOrderTabIndex', 0)
						uni.redirectTo({
							url: '/subPage1/socialized-service/farm-service/normalUser/myOrder/myOrder',
							animationType: 'pop-in',
							animationDuration: 200
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: "error"
						})
					}
				}).catch(errors => {
					console.log("失败信息:" + JSON.stringify(errors))
				})
			},
			back() {
				uni.redirectTo({
					url: `/subPage1/socialized-service/farm-service/normalUser/serviceSelect/service-organization/service-order`
				})
			},
			setcollapseheight() {
				let topheightone = uni.upx2px(136)
				let winHeight = 0
				uni.getSystemInfo({
					success: function(res) {
						winHeight = res.windowHeight
					}
				});
				let oldHeight = uni.upx2px(136)

				winHeight = parseInt(winHeight) - topheightone
				// #ifndef H5
				winHeight = winHeight

				// #endif
				return winHeight
			},
		}
	}
</script>

<style lang="scss" scoped>
	.service-price {
		position: relative;
		margin: 0 28rpx;
		margin-top: 10rpx;
		height: 240rpx;
		background: linear-gradient(360deg, #2165FF 0%, #88ACFF 100%);
		box-shadow: 0px 6px 6px 1px rgba(33, 222, 157, 0.05);
		border-radius: 14px 14px 14px 14px;

		.title {
			position: absolute;
			top: 0;
			left: 50%;
			transform: translateX(-50%);
			width: 244rpx;
			height: 62rpx;
			text-align: center;
			line-height: 62rpx;
			background: linear-gradient(180deg, #749FFF 0%, #004FFF 100%);
			color: #fff;
			// .left {
			// 	width: 0;
			// 	height: 0;
			// 	position: absolute;
			// 	top: 0;
			// 	border-width: 64rpx 0 0 31rpx;
			// 	border-color: #6494ff transparent transparent transparent; 
			// 	// opacity: 1;
			// 	border-style: solid;
			// 	transform: rotate(180deg);
			// }
		}

		.price {
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translateX(-50%) translateY(-50%);
			font-size: 30rpx;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #FFFFFF;
		}
	}

	/deep/.u-form {
		padding: 0 32rpx;
	}

	/deep/.u-form-item {
		position: relative;
		background-color: #fff;
		margin-top: 20rpx;
		border-radius: 20rpx;
	}

	/deep/.u-form-item {
		&:nth-child(1) {
			margin-top: 0;
			background-color: transparent;
		}

		&:nth-child(2) {
			display: flex;
			flex-wrap: wrap;
			margin-top: 0;
			background-color: transparent;
		}

		&:nth-child(3) {
			margin-top: 0;
			background-color: transparent;
		}
	}

	.left-image {
		position: absolute;
		// top: 50%;
		// transform: translateY(-50%);
		left: 0;
		width: 54rpx;
		height: 54rpx;
		border-radius: 50%;
		margin-left: 22rpx;
		display: flex;
		justify-content: center;
		align-content: center;
		flex-wrap: wrap;
	}

	.left-img {
		height: 26rpx;
	}

	/deep/ .u-form-item__body__left {
		width: 200rpx !important;
		margin-left: 50px;
	}

	/deep/ .u-checkbox-group--row {
		display: flex !important;
		flex-wrap: wrap !important;
		flex-shrink: 1;
	}

	.size {
		font-size: 24rpx;
		transform: scale(1.2);
		margin-right: 30rpx;
	}

	.total-prices {

		.prices {
			display: flex;
			justify-content: flex-end;
			align-items: center;

			.title {
				font-size: 32rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #606060;
			}

			.price {
				font-size: 32rpx;
				font-family: Arial-Bold, Arial;
				font-weight: bold;
				color: #2165FF;
			}
		}
	}

	// 提交
	.submit {
		position: fixed;
		bottom: 30rpx;
		left: 50%;
		transform: translateX(-50%);

		.submit-btn {
			width: 340rpx;
			height: 60rpx;
			line-height: 60rpx;
			background: linear-gradient(270deg, #88ACFF 0%, #2165FF 100%);
			box-shadow: 0px 0px 4px 1px rgba(0, 0, 0, 0.16);
			border-radius: 15px 15px 15px 15px;
			font-size: 28rpx;
			color: #FFFFFF;
			display: flex;
			justify-content: center;
			align-items: center;

			.icon-submit {
				margin-right: 10rpx;
			}
		}
	}

	// 空白
	.blank {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100%;
		align-items: center;
		justify-content: center;

		image {
			width: 104rpx;
			height: 114rpx;
		}

		.title {
			padding: 0 96rpx;
			padding-top: 38rpx;
			font-size: 32rpx
		}
	}

	// pop
	.popUpOperate {
		position: relative;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100rpx;
		padding: 0 20rpx;
		border-bottom: 1px solid #ccc;

		.left,
		.right {
			color: #0079fe;
		}

		.center {
			font-weight: 700;
		}
	}

	.popItem {
		.first {
			display: flex;
			flex-wrap: wrap;

			.popItemTop {
				width: 32%;
				height: 150rpx;
				margin-right: calc(4% / 2);
				margin-bottom: 20rpx;

				&:nth-child(3n) {
					margin-right: 0;
				}

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.tip {
			color: #d9001b;
			margin-bottom: 20rpx;
		}

		.title {
			font-size: 32rpx;
			font-weight: 700;
			margin-bottom: 20rpx;
		}
	}

	/deep/ .u-input__content {
		flex: none;
	}

	.fullAddress {
		display: flex;
		padding: 10rpx 0 !important;

		.textarea {
			width: 100%;
			padding: 0 !important;
			min-height: 114rpx !important;
			margin-right: 0;
		}

		/deep/.uni-textarea-textarea {
			padding: 2rpx !important;
			min-height: 114rpx !important;
		}

		/deep/ .uni-textarea-compute {
			flex: 1;
			min-height: 114rpx !important;
		}
	}

	/deep/.uni-textarea-wrapper {
		min-height: 114rpx !important;
	}
</style>